package com.ashlikun.flutter_anim_test

import android.os.Bundle
import android.util.Log
import com.ashlikun.flutter_anim_test.pigeons.PigeonsConfig
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.BasicMessageChannel
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.StandardMessageCodec


import io.flutter.embedding.android.FlutterActivity

class MainActivity : FlutterActivity()
 {
    private val CHANNEL = "samples.flutter.dev/MethodChannel"
    private val CHANNEL_BasicMessageChannel = "samples.flutter.dev/BasicMessageChannel"
    private val CHANNEL_EventChannel = "samples.flutter.dev/EventChannel"

    companion object {
        var methodChannel: MethodChannel? = null
        var eventChannel: EventChannel? = null
        var basicMessageChannel: BasicMessageChannel<Any>? = null
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        PigeonsConfig.configureFlutterEngine(flutterEngine)

//        FlutterBoost.instance().sendEventToFlutter("test", "test")
        basicMessageChannel = BasicMessageChannel<Any>(flutterEngine.dartExecutor.binaryMessenger, CHANNEL_BasicMessageChannel, StandardMessageCodec.INSTANCE)
        methodChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
        eventChannel = EventChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL_EventChannel)
        methodChannel?.setMethodCallHandler { call, result ->
            if (call.method == "getData1") {
                val value = 1
                if (value != -1) {
                    result.success(call.arguments)
                } else {
                    result.error("123", "value not available.", null)
                }
            } else {
                result.notImplemented()
            }
        }

        basicMessageChannel?.setMessageHandler { message, reply ->
            Log.d("MainActivity", "basicMessageChannel: $message")
            reply.reply("ok")
        }
    }
}


//
//package com.ashlikun.flutter_anim_test
//
//import android.os.Bundle
//import android.util.Log
//import com.ashlikun.flutter_anim_test.pigeons.PigeonsConfig
//import com.idlefish.flutterboost.containers.FlutterBoostActivity
//import io.flutter.embedding.engine.FlutterEngine
//import io.flutter.plugin.common.BasicMessageChannel
//import io.flutter.plugin.common.EventChannel
//import io.flutter.plugin.common.MethodChannel
//import io.flutter.plugin.common.StandardMessageCodec
//
//class MainActivity : FlutterBoostActivity() {
//    private val CHANNEL = "samples.flutter.dev/MethodChannel"
//    private val CHANNEL_BasicMessageChannel = "samples.flutter.dev/BasicMessageChannel"
//    private val CHANNEL_EventChannel = "samples.flutter.dev/EventChannel"
//
//    companion object {
//        var methodChannel: MethodChannel? = null
//        var eventChannel: EventChannel? = null
//        var basicMessageChannel: BasicMessageChannel<Any>? = null
//    }
//
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//
//    }
//
//    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
//        super.configureFlutterEngine(flutterEngine)
//        PigeonsConfig.configureFlutterEngine(flutterEngine)
//
////        FlutterBoost.instance().sendEventToFlutter("test", "test")
//        basicMessageChannel = BasicMessageChannel<Any>(flutterEngine.dartExecutor.binaryMessenger, CHANNEL_BasicMessageChannel, StandardMessageCodec.INSTANCE)
//        methodChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
//        eventChannel = EventChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL_EventChannel)
//        methodChannel?.setMethodCallHandler { call, result ->
//            if (call.method == "getData1") {
//                val value = 1
//                if (value != -1) {
//                    result.success(call.arguments)
//                } else {
//                    result.error("123", "value not available.", null)
//                }
//            } else {
//                result.notImplemented()
//            }
//        }
//
//        basicMessageChannel?.setMessageHandler { message, reply ->
//            Log.d("MainActivity", "basicMessageChannel: $message")
//            reply.reply("ok")
//        }
//    }
//}
